﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using C3.Proto.Core;
using C3.Proto.Core.Repository;
using C3.Proto.Core.Service;
using C3.Proto.Repo;
using StructureMap;
using StructureMap.Attributes;

namespace C3.Proto.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           
            routes.MapRoute(
                "Empty", "",
                new { controller = "Home", action = "Index", id = "" });
            routes.MapRoute(
                "Index", "Index",
                new { controller = "Home", action = "Index", id = "" });
            routes.MapRoute(
                "Default", "Default.aspx",
                new { controller = "Home", action = "Index", id = "" });

            routes.MapRoute(
               "Controller.Action.Id",                                              // Route name
               "{controller}/{action}/{id}",                           // URL with parameters
               new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
               );

            routes.MapRoute(
                "Controller.Action",
                "{controller}/{action}",
                new { action = "Index" }
                );


            routes.MapRoute(
               "Controller",
               "{controller}",
               new { action = "Index" }
               );
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            ObjectFactory.Initialize(service =>
             {

                
                 service.ForRequestedType<ISafetyService>().TheDefaultIsConcreteType<SafetyService>().CacheBy(InstanceScope.HttpSession);
                 //service.ForRequestedType<IUserService>().TheDefaultIsConcreteType<UserService>().CacheBy(InstanceScope.Singleton);
                 //service.ForRequestedType<ISessionManager>().TheDefaultIsConcreteType<SessionManager>().CacheBy(InstanceScope.HttpSession);
                 //service.ForRequestedType<IProfileService>().TheDefaultIsConcreteType<ProfileService>().CacheBy(InstanceScope.HttpSession);

                 ////Singletons
                 service.ForRequestedType<ISafetyRepo>().TheDefaultIsConcreteType<SafetyRepo>().CacheBy(InstanceScope.Singleton);
                 //service.ForRequestedType<IProfileRepository>().TheDefaultIsConcreteType<ProfileRepository>().CacheBy(InstanceScope.Singleton);

             });

        }
    }
}